<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>关键字：</label>
                    <input type="text" class="dggui-input dggui-input-large" id="searchKey" name="searchKey" placeholder="名称/编号" style="width: 190px;">
                </li>
                <li>
                    <button class="dggui-btn" onclick="tableReload();">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch()">清空条件</button>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <a href="javascript:void(0)" class="dggui-btn" onclick="addAssessmentLevel()">新增级别</a>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="assessmentLevel">

            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var tables;
    dggui.use(['table'], function (){
        var table = dggui.table;
        var opt={
            "elem":"#assessmentLevel",
            "ajax": sysInfo.basePath +"/rzsc/evaluating/assessment_level_list.do",
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                    //关键字
                    searchKey : $('#searchKey').val()
                });
                return aoData;
            },
            "aoColumns": [
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    'title': '级别',
                    "orderable": false,
                    "data": "level",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '最小分数',
                    "orderable": false,
                    "data": "min",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '最大分数',
                    "orderable": false,
                    "data": "max",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '描述',
                    "orderable": false,
                    "data": "remark",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '所属评估结果',
                    "orderable": false,
                    "data": "resultsName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '费率',
                    "orderable": false,
                    "data": "rate",
                    "render": function (data, type, full, meta) {
                        return data ? data : '0';
                    }
                },
                {
                    'title': '基准',
                    "orderable": false,
                    "data": "benchmark",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '合计',
                    "orderable": false,
                    "data": "combined",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<a href="javascript:addAssessmentLevel(\''+row.id+'\')" class="dggui-link">修改</a>' +
                            '&nbsp;&nbsp;<a href="javascript:deleteAssessmentLevel(\''+row.id+'\')" class="dggui-link">删除</a>';
                        return htm;
                    }
                }
            ]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });
    /**
     * 新增级别
     */
    function addAssessmentLevel(levelId){
        var title = "";
        if(isEmpty(levelId)){
            title = '新增级别';
        }else{
            title = '编辑级别';
        }
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/evaluating/add_assessment_level.html",
            data:{id:levelId},
            dataType:'html',
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: title,
                    content: res,
                    area: '600px',
                    yes: function (index) {
                        var level = $("#level").val();
                        var min = $("#min").val();
                        var max = $("#max").val();
                        var remark = $("#remark").val();
                        var rate = $("#rate").val();
                        var benchmark = $("#benchmark").val();
                        if(isEmpty(level)){
                            dggui.dialog.tip('级别不能为空！',$('#level'));
                            return;
                        }
                        if(isEmpty(min)){
                            dggui.dialog.tip('最小值不能为空！',$('#min'));
                            return;
                        }
                        if(isEmpty(max)){
                            dggui.dialog.tip('最大值不能为空！',$('#max'));
                            return;
                        }
                        if(isEmpty(remark)){
                            dggui.dialog.tip('说明不能为空！',$('#remark'));
                            return;
                        }
                        if(isEmpty(rate)){
                            dggui.dialog.tip('费率不能为空！',$('#rate'));
                            return;
                        }
                        if(isEmpty(benchmark)){
                            dggui.dialog.tip('基准不能为空！',$('#benchmark'));
                            return;
                        }
                        dggui.dialog.loading();
                        var evaluatingRatingLevel = serializeObject($("#addRatingLevelForm"));
                        $.ajax({
                            url: sysInfo.basePath + "/rzsc/evaluating/save_rating_level.do",
                            type:'POST',
                            data: evaluatingRatingLevel,
                            dataType : "JSON",
                            success: function (res) {
                                dggui.dialog.loading('close');
                                if (res.code == 0) {
                                    dggui.dialog.succeed(res.msg);
                                    layer.close(index);
                                    tableReload();
                                } else {
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });
                    }
                })
            }
        });
    }

    /**
     * 删除客户级别
     * @param id
     */
    function deleteAssessmentLevel(id) {
        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
            dggui.dialog.loading();
            $.ajax({
                url: sysInfo.basePath + "/rzsc/evaluating/delete_assessment_level.do",
                data: {id: id},
                success: function (res) {
                    dggui.dialog.loading('close');
                    if (res.code == 0) {
                        dggui.dialog.succeed(res.msg);
                        tableReload();
                    } else {
                        dggui.dialog.errors(res.msg);
                    }
                }
            });

        })

    }

    //列表刷新
    function tableReload() {
        tables.ajax.reload();
    }
</script>
</body>
</html>